#include "common/types.h"
#include "math.h"
#include <QString>

/**

  *
  */
Point3D &Point3D::operator *(double c)
{
    x *= c;
    y *= c;
    z*= c;

    return *this;
}

/**
  *
  */
Point3D &Point3D::rotate(Axis axis, double angle)
{

    double *fstc, *sndc;

    switch(axis)
    {
        case AXIS_X:
            fstc = &y;
            sndc = &z;
            break;
        case AXIS_Y:
            fstc = &x;
            sndc = &z;
            break;
        case AXIS_Z:
            fstc = &x;
            sndc = &y;
            break;
    }

    double fst_temp = *fstc;
    double snd_temp = *sndc;

    *fstc = ((fst_temp * cos(angle)) - (snd_temp * sin(angle)));
    *sndc = ((fst_temp * sin(angle)) + (snd_temp * cos(angle)));

    return *this;
}

/**
  *
  */
Point3D &Point3D::scale(double c)
{
    return (this->operator *(c));
}

/**
  *
  */
Point3D &Point3D::translate(const Point3D &tp)
{
    x = (x + tp.x);
    y = (y + tp.y);
    z = (z + tp.z);

    return *this;
}

/**
  *
  */
double Point3D::distance(const Point3D &p) const
{
    double d1, d2, d3;
    double dist;

    d1 = x - p.x;
    d2 = y - p.y;
    d3 = z - p.z;

    dist = sqrt((d1 * d1) + (d2 * d2) + (d3 * d3));

    return dist;
}
/**
  *
  */
void Point3D::show() const
{
    cout << "P: (" << x << ", " << y << ", " << z << ")" << endl;
}

const QString Point3D::rep() const
{
    QString _rep("(");

    _rep.append(QString::number(x)).append(", ");
    _rep.append(QString::number(y)).append(", ");
    _rep.append(QString::number(z)).append(")");

    return _rep;
}

//
//
//

/**
  *
  */
Point3D *operator -(const Point3D &p0, const Point3D &p1)
{
    double x, y, z;

    x = p1.x - p0.x;
    y = p1.y - p0.y;
    z = p1.z - p0.z;

    return new Point3D(x, y, z);
}
